<?php
class order extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的

		$this->tit = '订单';

		$this->orderObj = D('site_order');
		$this->order_logObj = D('site_order_log');
		$this->areaObj = D('site_area');
		$this->cateObj = D('site_cate');
		$this->zoneObj = D('site_zone');
		$this->deviceObj = D('site_device');
		$this->adminObj = D('site_admin');

		$this->area_list = $this->areaObj->get_treeList("status=1 ".$this->cond_base);
		$this->cate_list = $this->cateObj->get_treeList("status=1 ".$this->cond_base);
		$this->zone_list = $this->zoneObj->get_treeList("status=1 ".$this->cond_base);
		// $this->shifu_list = $this->adminObj->get_TreeList("status=1 ".$this->cond_base);
		// $this->search = array('shifu_id'=>'1','time_s'=>'1');
	}
    
    //列表
	public function index(){
		/*分类切换*/
		$this->tabtit = array_merge(array('全部'),$this->orderStatus);

		$cond = "status=1 ".$this->cond_base;
		// 加入查询条件
		if($this->tab){
			switch($this->tab){
				case '8':
					$cond .=" and order_status=99";
					break;
				default:
					$cond .=" and order_status={$this->tab}";
			}
		}
		// dump($cond);exit;
		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%') ";
		}
		
		$result = $this->orderObj->get_list($cond);
        if($result){
			$this->areas = $this->areaObj->ids($result['list'],'area_id');
			$this->cates = $this->cateObj->ids($result['list'],'cate_id');
			$this->zones = $this->zoneObj->ids($result['list'],'zone_id');
			$this->admins = $this->adminObj->ids($result['list'],'admin_id');
			$this->shifus = $this->adminObj->ids($result['list'],'shifu_id');
			$this->devices = $this->deviceObj->ids($result['list'],'device_id');

        	$this->list = $result['list'];
			$this->showPage = $result['showPage'];
			$this->total = $result['total'];
		}
		
	}


	//隐藏
	// public function ban(){
	// 	$id = arg('id');
	// 	if($this->isAjax()){
	// 		$res = $this->modelObj->act($id,0);
	// 		$this->renderSuccess('隐藏成功');
	// 	}
	// }

	// //显示
	// public function act(){
	// 	$id = arg('id');
	// 	if($this->isAjax()){
	// 		$res = $this->modelObj->act($id,1);
	// 		$this->renderSuccess('显示成功');
	// 	}
	// }

    // //删除
	// public function del(){
	// 	$id = arg('id');
	// 	if($this->isAjax()){
	// 		$res = $this->modelObj->del($id);
	// 		$this->renderSuccess('删除成功');
	// 	}
	// }
	
	// //排序
	// public function sort() {
    //     $sort = arg('sort');
	// 	$result = $this->modelObj->sort($sort);
	// 	$this->renderSuccess('排序成功');
    // }

	// //详情
	// public function detail(){
	// 	$id = arg('id');
	// 	$info = $this->modelObj->get_detail($id);
		
	// 	$this->info = $info;
	// }

	//导出
	public function export(){
		// $id = arg('id');
		// if($this->isAjax()){
		// 	$cond = "status=1".$this->cond_base;

		// 	$data = $this->postData('data');

		// 	$result = $this->orderObj->exportList($cond,$data);

		// 	$this->renderSuccess('导出成功');
		// }
		// $this->info = $this->orderObj->findById($id);
	}

	//导出
	public function export_csv(){

		$data = $this->postData('data');

		$cond = "status=1".$this->cond_base;
		if($data['order_status']){
			switch($data['order_status']){
				case '8':
					$cond .=" and order_status=99";
					break;
				default:
					$cond .=" and order_status={$data['order_status']}";
			}
		}
		if($data['keyword']){
			$cond .=" and (title like '%".$data['keyword']."%') ";
		}
		
		$result = $this->orderObj->exportList($cond,$data);
		
	}

	

	//导入
	public function import(){
		$id = arg('id');
		if($this->isAjax()){
		
			$data = $this->postData('data');
			$csvData = $this->orderObj->getCsvData();
			$res = $this->orderObj->importList($csvData);

			dump($res);exit;

			$this->renderSuccess('导入成功', "/{$this->routeUrl}/index");
		}
		$this->info = $this->orderObj->findById($id);
	}

	//导入
	public function deliveryTpl(){
		$this->orderObj->deliveryTpl();
	}

}